#include <myheader_c_plus.h>
using std::endl;
using std::cout;
class Point{
public:
    //无参构造
    Point(){}
    
    //构造函数
    Point(float x, float y)
    :_x(x)
    ,_y(y)
    {

    }

    //拷贝构造函数
    Point(const Point & rhs)
    :_x(rhs._x)
    ,_y(rhs._y)
    {

    }

    //获得两点之间距离
    float getDistance(const Point & pt){
        return sqrt(pow(_x - pt._x, 2) + pow(_y - pt._y, 2));
    }


private:
    float _x;
    float _y;
};


class Color{

public:
    //无参构造
    Color()
    :_color(new char[1]())
    {

    }

    //构造函数
    Color(const char * color)
    :_color(new char[strlen(color) + 1]())
    {
        strcpy(_color, color);
    }

    //拷贝构造函数
    Color(const Color & rhs)
    :_color(new char[strlen(rhs._color) + 1]())
    {
        strcpy(_color, rhs._color);
    }


    //赋值运算函数
    Color & operator=(const Color & rhs){
        if(this != &rhs){
            delete [] _color;
            _color = new char[strlen(rhs._color) + 1]();
            strcpy(_color, rhs._color);
        }
        return *this;
    }


    //析构函数
    ~Color(){
        if(_color){
            delete [] _color;
            _color = nullptr;
        }
    }

    //获得颜色
    char * getColor(){
        return _color;
    }
    

private:
    char * _color;
};



class Line{
public:
    //无参构造
    Line(){}


    //构造函数
    Line(float x1, float y1, float x2, float y2)
    :_pt1(x1, y1)
    ,_pt2(x2, y2)
    {

    }

    
    //拷贝构造函数
    Line(const Line & rhs)
    :_pt1(rhs._pt1)
    ,_pt2(rhs._pt2)
    {

    }

    //获得长度
    float getLength(){
        return _pt1.getDistance(_pt2);
    }


private:
    Point _pt1;
    Point _pt2;
};


class Triangle : public Line, public Color{
public:
    //无参构造函数
    Triangle(){}

    //构造函数
    Triangle(float x1, float y1, float x2, float y2, float height, const char * color)
    :Line(x1, y1, x2, y2)
    ,Color(color)
    ,_height(height)
    {

    }
    
    //获得周长
    float getPerimeter(){
        float eage = sqrt(_height * _height + getLength() * getLength());
        return eage + _height + getLength();
    }


    //获得面积
    float getArea(){
        return (getLength() * _height) / 2;
    }



private:
    float _height;
};
int main(int argc, char *argv[])
{
    Triangle t(0, 0, 0, 3, 4, "red");
    t.getColor();
    cout << t.getArea() << " " << t.getPerimeter() << endl;
    return 0;
}

